""" 应用工厂 """

from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from app.routes import auth_bp  # 从routes包导入
from app.extensions import db, migrate, limiter
from app.config import Config

print(" * 应用启动完成！修改文件测试热重载...")
def create_app(config_class=Config):
    """ 创建APP """
    app = Flask(__name__)
    app.config.from_object(config_class)

    # 初始化扩展
    # CORS(app,origins='*')
    CORS(app, resources={
        r"/api/*": {
            "origins": "*",
            "methods": ["GET", "POST", "OPTIONS"],
            "allow_headers": ["Content-Type"]
        }
    })
    JWTManager(app)
    db.init_app(app)
    migrate.init_app(app, db)
    limiter.init_app(app)

    # 注册蓝图
    app.register_blueprint(auth_bp, url_prefix='/api/auth')

    return app
